import { request } from '@/plugins/http';

export const apiGetArticles = async (params?: any) => {
  const result = await request('admin/articles', {
    params: { ...params },
  });
  return result;
};

// 文章详情
export const apiGetArticle = (id: number) => {
  return request(`admin/article/${id}`);
};

// 编辑文章
export const apiPostArticle = (data: any) => {
  return request('admin/article/post', {
    method: 'POST',
    data,
  });
};

// 获取文章分类
export const apiGetArticleCategories = async () => {
  const result = await request('admin/article/categories');
  return { list: result.data.items };
};

// 新增 / 编辑文章分类
export const apiPostArticleCategory = (data: any) => {
  return request('admin/article/category', {
    method: 'POST',
    data,
  });
};

// 删除文章分类
export const apiDeleteArticleCategory = (id: number[]) => {
  return request('admin/article/category', {
    method: 'DELETE',
    data: { id },
  });
};
